//
//  AddZTCarFromCarDetailController.m
//  CarTown
//
//  Created by xionghao on 15/9/12.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "AddZTCarFromCarDetailController.h"
#import "AddZTCarHeadTableViewCell.h"
#import "Pubmode.h"
#import "CarpubMode.h"
#import "PublishTopTableViewCell.h"
#import "JianjieViewController.h"
#import "ListPikerController.h"
#import "Position.h"
#import "Area.h"
#import "Process.h"
#import "FindCarTableViewController.h"
#import "CarsrouceTypePickerController.h"
#import "CarPickModel.h"
#import "CarSourceType.h"
#import "Puser.h"
#import "ColorPickViewController.h"
#import <QBImagePickerController/QBImagePickerController.h>
#import "CarbrandModel.h"
#import "CarprogChildmode.h"
#import "ColorPickViewController.h"
#import "FindCarTableViewController.h"
#import "RadioTableViewCell.h"
#import "EditCarTableViewCell.h"
#import "CarDetail.h"
#import "ListPikerController.h"
#import "LongPeizhi.h"
#import "AddCarPeizhiTableViewCell.h"
#import "addCarImagePickerTableViewCell.h"
#import "EidtTableViewCell.h"
#import "RadioTableViewCell.h"
#import "JianjieViewController.h"
#import "ShareView.h"
#import "Puser.h"
#import "CarSourceType.h"
#import "PostSUSViewController.h"
#import "PostResdemode.h"
@interface AddZTCarFromCarDetailController ()<addCarImagePickerViewCellDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,QBImagePickerControllerDelegate,ShareclickDelegate,EidtTableViewCellDelegate,UITableViewDataSource,UITableViewDelegate,PostSUSViewControllerDelegate>
@property (nonatomic,strong) Pubmode *waiguan;
@property (nonatomic,strong) Pubmode *neishi;
@property (nonatomic,strong) Pubmode *paifang;
@property (nonatomic,strong) Pubmode *heji;
@property (nonatomic,strong) Pubmode *cheshen;
@property (nonatomic,strong) Pubmode *zonghe;
@property (nonatomic,strong) Pubmode *gouzhi;
@property (nonatomic,strong) Pubmode *shangpai;
@property (nonatomic,strong) Pubmode *qita;
@property (nonatomic,strong) Pubmode *youhui;
@property (nonatomic,strong) Pubmode *quanbao;
@property (nonatomic,strong) CarpubMode *carmode;
@property (nonatomic,strong) LongPeizhi *peizhi;
@property (nonatomic,strong) NSMutableArray *dataarray;
@property (nonatomic,strong) Pubmode *beizhu;
@property (nonatomic,strong) addCarImagePickerTableViewCell *currtcell;
@property (nonatomic,strong) UIButton *button;
@property (nonatomic,strong) UIImagePickerController *picker;
@property (nonatomic,strong) Puser *user;
@property (nonatomic,strong) UITableView *tableView;
@end

@implementation AddZTCarFromCarDetailController

-(Puser *)user{
    if (_user==nil) {
        _user=[Puser getUser];
    }
    return _user;
}

+(instancetype)viewcontroller{
    AddZTCarFromCarDetailController *vc=[[AddZTCarFromCarDetailController alloc]init];
    return vc;
}
-(UITableView *)tableView{
    if (_tableView==nil) {
        _tableView=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        [self.view addSubview:_tableView];
    }
    return _tableView;
}
-(UIImagePickerController *)picker{
    if (_picker==nil) {
        _picker=[[UIImagePickerController alloc]init];
        _picker.view.backgroundColor = [UIColor whiteColor];
        
        _picker.delegate =self;
        _picker.allowsEditing = YES;
    }
    return _picker;
}

-(NSMutableArray *)dataarray{
    if ( _dataarray==nil) {
        _dataarray=[NSMutableArray array];
    }
    return  _dataarray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    self.navigationItem.title=self.cardetail.car_name;
//    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"top-r-two"] style:UIBarButtonItemStyleDone target:self action:@selector(share)];
    self.tableView.backgroundColor=bgGarycolor;
    [self setupdata];
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
        
    }
    
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
        
    }
    [self setuppostbtn];
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.1;
}



-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}
-(void)share{
    NSArray *titlearray=@[@"微信",@"朋友圈",@"短信"];
    UIImage *weixin=[UIImage imageNamed:@"weixin"];
    UIImage *pengyou=[UIImage imageNamed:@"liulan"];
    UIImage *sms=[UIImage imageNamed:@"duanxin"];
    NSArray *icon=@[weixin,pengyou,sms];
    ShareView *share=[[ShareView alloc]initWithTitle:titlearray andIcons:icon delegate:self];
    [share show];
}

-(void)photoCellView:(addCarImagePickerTableViewCell *)cell  pickerBtnClick:(NSInteger)index withButton:(UIButton *)btn{
   
        self.button=btn;
        self.currtcell=cell;
        
        if (index==0) {
            UIImagePickerControllerSourceType sourcheType = UIImagePickerControllerSourceTypeCamera;
            self.picker.sourceType=sourcheType;
            [self presentViewController:self.picker animated:YES completion:nil];
        }else{
            
            
            NSIndexPath *indexpath=[self.tableView indexPathForCell:cell];
            NSArray *array=self.dataarray[indexpath.section];
            CarpubMode *photomode=array[indexpath.row];
            
            
            QBImagePickerController *imagePickerController = [QBImagePickerController new];
            imagePickerController.delegate = self;
            imagePickerController.allowsMultipleSelection = YES;
            if (btn.isSelected) {
                imagePickerController.maximumNumberOfSelection = 1;
            }else{
                imagePickerController.maximumNumberOfSelection = 8-photomode.imgarray.count;
            }
            imagePickerController.showsNumberOfSelectedAssets = YES;
            
            
            [self presentViewController:imagePickerController animated:YES completion:NULL];
        }
    }
    

#pragma -mark 颜色选择回调
-(void)ColorPikcerClickContoller:(ColorPickViewController *)picker withIndex:(NSInteger)index ColorStr:(NSString *)colorstr{
    NSIndexPath *indexpath;
    if(picker.view.tag==0){
        self.waiguan.detail=colorstr;
        self.waiguan.index=index;
        indexpath=[NSIndexPath indexPathForRow:2 inSection:0];
        
    }else{
        self.neishi.detail=colorstr;
        self.neishi.index=index;
        indexpath=[NSIndexPath indexPathForRow:3 inSection:0];
    }
    [self.tableView reloadRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
-(void)setuppostbtn{
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, XHScreenwidth, 64)];
    UIButton *postbtn=[[UIButton alloc]initWithFrame:CGRectMake(16, 16, XHScreenwidth-32, 36)];
    [postbtn setBackgroundImage:[UIImage imageNamed:@"bottom_bg"] forState:UIControlStateNormal];
    [postbtn setTitle:@"加入展厅" forState:UIControlStateNormal];
    [postbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [postbtn addTarget:self action:@selector(postclick) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:postbtn];
    self.tableView.tableFooterView=view;
}
-(void)postclick{
    if ([self checkform]) {
        
        MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        hud.labelText=@"正在添加...";
        hud.margin = 10.f;
        hud.removeFromSuperViewOnHide = YES;
        
        NSMutableDictionary *params=[NSMutableDictionary dictionary];
        params[@"action"]=@"add_display";
        
        NSInteger power=[self.user.power integerValue];
        if (power<5) {
            params[@"type"]=@"person";
            params[@"user_id"]=self.user.user_id;
        }else{
           params[@"type"]=@"company";
           params[@"user_id"]=self.user.com_id;
            
        }
        CarSourceType *type=[CarSourceType getcarsoucebyText:self.cardetail.car_source_type];
        params[@"type_id"]=type.csid;
        params[@"mid"]=self.cardetail.mid;
        params[@"brand_id"]=self.cardetail.b_id;
        params[@"cat_name"]=self.cardetail.car_name;
        params[@"price_zdj"]=self.cheshen.detail;
        params[@"yhprice"]=self.youhui.detail;
        params[@"car_inside_color"]=self.neishi.detail;
        params[@"car_outside_color"]=self.waiguan.detail;
        if (self.paifang.radioindex!=-1) {
            switch (self.paifang.radioindex) {
                case 0:
                    params[@"standard"]=@"4";
                    break;
                case 1:
                    params[@"standard"]=@"5";
                    break;
                case 2:
                    params[@"standard"]=@"0";
                    break;
                default:
                    break;
            }
            
        }
        if ([self.peizhi.loogdetail isEqualToString:@""]) {
            params[@"car_configure"]=self.peizhi.loogdetail;
        }
        
        if ([self.gouzhi.detail integerValue]!=0) {
            params[@"price_gzs"]=self.gouzhi.detail;
        }
        if ([self.shangpai.detail integerValue]!=0) {
            params[@"price_spf"]=self.shangpai.detail;
        }
        if ([self.zonghe.detail integerValue]!=0) {
            params[@"price_zhx"]=self.zonghe.detail;
        }if ([self.qita.detail integerValue]!=0) {
            params[@"price_other"]=self.qita.detail;
        }
        
        params[@"allprice"]=self.quanbao.detail;
        params[@"sysprice"]=self.heji.detail;
        
        if (self.carmode.imgarray.count>0) {
            
            NSMutableArray *imgstrarray=[NSMutableArray array];
            
            for (UIImage *image in self.carmode.imgarray) {
                NSData *imagedata=[UIImage compressData:image toMaxFileSize:DefailutPicSize];
                NSString *base64str=[imagedata imageBase64Data:imagedata];
                [imgstrarray addObject:base64str];
            }
            NSString *imgp=[NSString DataTOjsonString:imgstrarray];
            params[@"pic"]=imgp;
        }
        [PostUitls Post:myzturl parameters:params success:^(id response) {
            PostResdemode *resd =[PostResdemode objectWithKeyValues:response];
            hud.mode=MBProgressHUDModeText;
            if ([resd.state integerValue]==400) {
                
                PostSUSViewController *svc=[PostSUSViewController viewcontroller];
                svc.delegate=self;
                svc.type=POSTADDZTCARFROMCARDETAIL;
                svc.ID=[NSString stringWithFormat:@"%ld",[resd.data integerValue]];
                
                [self.navigationController pushViewController:svc animated:YES];
            }else{
                hud.labelText=resd.msg;
            }
            [hud hide:YES afterDelay:1];

            
            
        } failure:^(NSError *error) {
             hud.mode=MBProgressHUDModeText;
            hud.labelText=@"网络错误";
            [hud hide:YES afterDelay:1];
        }];
        
        
    }
}
-(BOOL)checkform{
    if ([self.cheshen.detail integerValue]==0||[self.cheshen.detail isEqualToString:@""]||self.cheshen.detail==nil) {
        MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        hud.labelText=@"请输入车身价";
        hud.mode = MBProgressHUDModeText;
        hud.margin = 10.f;
        hud.removeFromSuperViewOnHide = YES;
        [hud hide:YES afterDelay:1];
        return NO;
    }
    
    if ([self.youhui.detail isEqualToString:@""]||self.youhui.detail==nil) {
        MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        hud.labelText=@"请输入优惠价";
        hud.mode = MBProgressHUDModeText;
        hud.margin = 10.f;
        hud.removeFromSuperViewOnHide = YES;
        [hud hide:YES afterDelay:1];
        return NO;
    }
    
    return YES;
}
-(void)textFieldChange:(EidtTableViewCell *)cell{
    NSIndexPath *indexpath=[self.tableView indexPathForCell:cell];
    if ((indexpath.section==1&&indexpath.row>1&&indexpath.row<6)||(indexpath.section==1&&indexpath.row==7)) {
        NSInteger heji=[self.cheshen.detail integerValue]+[self.gouzhi.detail integerValue]+[self.shangpai.detail integerValue]+[self.qita.detail integerValue];
        self.heji.detail=[NSString stringWithFormat:@"%ld",heji];
        NSInteger youhui=heji-[self.youhui.detail integerValue];
        NSMutableArray *marray=[NSMutableArray array];
        NSIndexPath *indexpath=[NSIndexPath indexPathForRow:6 inSection:1];
         NSIndexPath *indexpath2=[NSIndexPath indexPathForRow:8 inSection:1];
        [marray addObject:indexpath];
        [marray addObject:indexpath2];
        if (youhui<0) {
            MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
            hud.labelText=@"综合优惠不能大于合计价格";
            hud.mode = MBProgressHUDModeText;
            hud.margin = 10.f;
            hud.removeFromSuperViewOnHide = YES;
            [hud hide:YES afterDelay:1];
            self.youhui.detail=nil;
            NSIndexPath *indexpath3=[NSIndexPath indexPathForRow:7 inSection:1];
            [marray addObject:indexpath3];
            
        }else{
            self.quanbao.detail=[NSString stringWithFormat:@"%ld",youhui];
        }
        
        
        
        [self.tableView reloadRowsAtIndexPaths:marray withRowAnimation:UITableViewRowAnimationAutomatic];
        
    }
}

-(void)setupdata{
    
    Pubmode *header=[[Pubmode alloc]init];
    header.name=self.cardetail.car_name;
    header.detail=[NSDate dateStrFromTimeStr:self.cardetail.addtime];
    header.rowheight=60;
    
    Pubmode *leixing=[[Pubmode alloc]init];
    leixing.name=@"车源类型";
    leixing.isMust=YES;
    leixing.isNeedHideA=YES;
    leixing.detail=self.cardetail.car_source_type;
    
    
    Pubmode *waiguan=[[Pubmode alloc]init];
    waiguan.name=@"外观颜色";
    
    waiguan.detail=self.cardetail.car_outside_color;
    waiguan.block=^{
        
       
            ColorPickViewController *color=[ColorPickViewController colorpicker];
            color.delegate=self;
            
            color.ID=self.cardetail.ID;
            color.index=self.waiguan.index;
            color.colorstr=self.waiguan.detail;
            color.isOut=YES;
            color.view.tag=0;
            [self.navigationController pushViewController:color animated:YES];
    };
    self.waiguan=waiguan;
    Pubmode *neishi=[[Pubmode alloc]init];
    neishi.name=@"内饰颜色";
   
    neishi.detail=self.cardetail.car_inside_color;
    self.neishi=neishi;
    neishi.block=^{
         ColorPickViewController *color=[ColorPickViewController colorpicker];
            color.delegate=self;
            color.ID=self.cardetail.ID;
            color.index=self.neishi.index;
            color.colorstr=self.waiguan.detail;
            color.isOut=NO;
            color.view.tag=1;
        [self.navigationController pushViewController:color animated:YES];
        
    };
    Pubmode *paifang=[[Pubmode alloc]init];
    paifang.name=@"排放标准";
    paifang.isMust=NO;
    paifang.titlearray=@[@"国四",@"国五",@"不限"];
    NSInteger p= [self.cardetail.standard integerValue];
    switch (p) {
        case 0:
             paifang.radioindex=2;
            break;
        case 4:
            paifang.radioindex=0;
            break;
        case 5:
            paifang.radioindex=1;
            break;

        default:
            paifang.radioindex=-1;
            break;
    }
   
    
   
    self.paifang=paifang;
    
    LongPeizhi *peizhi=[[LongPeizhi alloc]init];
    peizhi.name=@"配置";
    peizhi.isMust=YES;
    peizhi.loogdetail=self.cardetail.car_configure&&![self.cardetail.car_configure isEqualToString:@""]?self.cardetail.car_configure:@"请输入";
    peizhi.block=^{
        JianjieViewController *jjvc=[JianjieViewController viewcontroller];
        jjvc.textlength=500;
        jjvc.navtitle=peizhi.name;
        jjvc.text=[peizhi.loogdetail isEqualToString:@"请输入"]?@"":peizhi.loogdetail;
        jjvc.block=^(NSString *str){
            if (str==nil) {
                peizhi.loogdetail=@"请输入";
            }else{
                peizhi.loogdetail=str;
            }
            
            
            NSIndexPath *indepath=[NSIndexPath indexPathForRow:5 inSection:0];
            [self.tableView reloadRowsAtIndexPaths:@[indepath] withRowAnimation:UITableViewRowAnimationAutomatic];
        };
        [self.navigationController pushViewController:jjvc animated:YES];
    };
    CarpubMode *carmode=[[CarpubMode alloc]init];
    carmode.name=@"车辆图片";
    carmode.isPhotoCell=YES;
    carmode.imgarray=self.photomode.imagearray?self.photomode.imagearray:[NSMutableArray array];
    
    CGFloat imgwith=60;
    self.carmode=carmode;
    NSArray *infoarray=@[header,leixing,waiguan,neishi,paifang,peizhi,carmode];
    [self.dataarray addObject:infoarray];
    
    Pubmode *name=[[Pubmode alloc]init];
    name.name=self.cardetail.car_name;
    name.isNeedHideA=YES;
    name.rowheight=30;
    name.detail=nil;
    name.isNormal=YES;
    Pubmode *cheshen=[[Pubmode alloc]init];

    cheshen.isEidt=YES;
    cheshen.placehoder=@"请输入车身价";
    cheshen.pricetitle=@"元";
     cheshen.name=@"车身指导价";
    cheshen.limitlength=5;
    cheshen.isMust=YES;
    if ([self.cardetail.sprice floatValue]*10000!=0) {
        NSInteger price=[self.cardetail.sprice floatValue]*10000;
        
        cheshen.detail=[NSString stringWithFormat:@"%ld",price];
       
       
    }
    
    cheshen.yuancolor=tintblue;
    self.cheshen=cheshen;
    Pubmode *gouzhi=[[Pubmode alloc]init];
    gouzhi.name=@"购置税";
    gouzhi.placehoder=@"请输入购置税金额";
    gouzhi.isEidt=YES;
    gouzhi.pricetitle=@"元";
    self.gouzhi=gouzhi;
    Pubmode *shangpai=[[Pubmode alloc]init];
    shangpai.name=@"上牌费";
    shangpai.isEidt=YES;
    shangpai.pricetitle=@"元";
    shangpai.placehoder=@"请输入上牌费金额";
    self.shangpai=shangpai;
    Pubmode *zonghe=[[Pubmode alloc]init];
    zonghe.name=@"综合险";
    zonghe.isEidt=YES;
    zonghe.pricetitle=@"元";
    zonghe.placehoder=@"请输入综合险金额";
    self.zonghe=zonghe;
    Pubmode *qita=[[Pubmode alloc]init];
    qita.name=@"其他费用";
    qita.isEidt=YES;
    qita.placehoder=@"0";
    qita.pricetitle=@"元";
    self.qita=qita;
    Pubmode *heji=[[Pubmode alloc]init];
    heji.name=@"合计";
    heji.placehoder=@"自动生成";
    heji.pricetitle=@"元";
    heji.yuancolor=tintblue;
    heji.isAluto=YES;
    self.heji=heji;
    Pubmode *zongheyouhui=[[Pubmode alloc]init];
    zongheyouhui.name=@"综合优惠";
    zongheyouhui.isEidt=YES;
    zongheyouhui.placehoder=@"请输入综合优惠金额";
    zongheyouhui.isMust=YES;
    zongheyouhui.pricetitle=@"元";
    self.youhui=zongheyouhui;
    Pubmode *quanbao=[[Pubmode alloc]init];
    quanbao.name=@"最终价格";
    quanbao.placehoder=@"自动生成";
    quanbao.pricetitle=@"元";
    quanbao.yuancolor=tintblue;
    quanbao.isAluto=YES;
    self.quanbao=quanbao;
    Pubmode *beizhu=[[Pubmode alloc]init];
    beizhu.name=@"备注";
    beizhu.detail=@"请输入";
    beizhu.block=^{
        JianjieViewController *jjvc=[JianjieViewController viewcontroller];
        jjvc.textlength=500;
        jjvc.navtitle=beizhu.name;
        jjvc.text=[beizhu.detail isEqualToString:@"请输入"]?@"":beizhu.detail;
        jjvc.block=^(NSString *str){
            if (str==nil) {
                beizhu.detail=@"请输入";
            }else{
            beizhu.detail=str;
            }
            NSIndexPath *indepath=[NSIndexPath indexPathForRow:9 inSection:1];
            [self.tableView reloadRowsAtIndexPaths:@[indepath] withRowAnimation:UITableViewRowAnimationAutomatic];
        };
        [self.navigationController pushViewController:jjvc animated:YES];
    };
    NSArray *array=@[name,cheshen,gouzhi,shangpai,zonghe,qita,heji,zongheyouhui,quanbao,beizhu];
    self.beizhu=beizhu;
    [self.dataarray addObject:array];
    
}


-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    [self.view endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return self.dataarray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    NSArray *array=self.dataarray[section];
    return array.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return 0.1;
    }else{
        return 36;
    }
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return nil;
    }else{
        UILabel *bgview=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, XHScreenwidth, 36)];
        bgview.backgroundColor=UIColorWithRGB(227, 235, 239);
        bgview.textColor=textnormalGary;
        bgview.text=@"购车预算";
        bgview.font=[UIFont systemFontOfSize:14];
        bgview.textAlignment=NSTextAlignmentCenter;
        return bgview;
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *array=self.dataarray[indexPath.section];
    
    Pubmode *mode=array[indexPath.row];
    if (mode.block) {
        mode.block();
    }
}

-(void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController{
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
         // Configure the cell...
    NSArray *array=self.dataarray[indexPath.section];
    
    Pubmode *mode=array[indexPath.row];
    
    if (indexPath.row==0&&indexPath.section==0) {
        AddZTCarHeadTableViewCell *headercell=[AddZTCarHeadTableViewCell cellWithTableView:tableView];
        headercell.carnamelable.text=mode.name;
        headercell.timelable.text=mode.detail;
        return headercell;
    }else if ([mode isKindOfClass:[LongPeizhi class]]){
     
        LongPeizhi *peizhi=mode;
        AddCarPeizhiTableViewCell *cell=[AddCarPeizhiTableViewCell cellWithTableView:tableView];
        
        
        cell.titlelabel.text=peizhi.name;
        cell.longdetail.text=peizhi.loogdetail;
        if ([peizhi.loogdetail isEqualToString:@"请输入"]) {
            cell.longdetail.textColor=placehodlerColor;
        }else{
            cell.longdetail.textColor=textnormalGary;
        }
        return cell;
    }else  if (mode.titlearray) {
        RadioTableViewCell *cell=[RadioTableViewCell cellWithTablView:tableView];
        cell.mode=mode;
        return cell;
    }else if (mode.isEidt||mode.isAluto){
        EidtTableViewCell *cell=[EidtTableViewCell cellWithTable:tableView];
        cell.delegate=self;
        cell.mode=mode;
        if (mode.isAluto) {
            cell.detail.enabled=NO;
            cell.price.textColor=mode.yuancolor;
            cell.titlelable.textColor=mode.yuancolor;
        }else{
            if (mode.yuancolor) {
                cell.price.textColor=mode.yuancolor;
                cell.titlelable.textColor=mode.yuancolor;
            }else{
            cell.price.textColor=textnormalGary;
            cell.detail.enabled=YES;
            cell.titlelable.textColor=textnormalGary;
            }
        }
        return cell;
    } else if ([mode isKindOfClass:[CarpubMode class]]){
        CarpubMode *imgmode=mode;
        addCarImagePickerTableViewCell *cell=[addCarImagePickerTableViewCell cellWithTablView:tableView];
        cell.mode=imgmode;
        cell.delegate=self;
        return cell;
    }
    else{
        PublishTopTableViewCell *cell=[PublishTopTableViewCell cellWithTableView:tableView];
        cell.mode=mode;
        cell.detail.hidden=mode.isNormal;
        if (mode.isNeedHideA) {
            cell.accessoryType=UITableViewCellAccessoryNone;
        }else{
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            
        }
        if (mode.detail==nil||[mode.detail isEqualToString:@"请选择"]||[mode.detail isEqualToString:@"请输入"]) {
            cell.detail.textColor=placehodlerColor;
        }else{
            cell.detail.textColor=textnormalGary;
        }
       return cell;

    }

}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    [self dismissViewControllerAnimated:YES completion:^{
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
        
        NSIndexPath *indexpath=[self.tableView indexPathForCell:self.currtcell];
        NSArray *array=self.dataarray[indexpath.section];
        CarpubMode *photomode=array[indexpath.row];
        photomode.ischange=YES;
        if (self.button.isSelected) {
            [photomode.imgarray replaceObjectAtIndex:self.button.tag withObject:image];
        }else{
            [photomode.imgarray addObject:image];
        }
     
    }];
}

-(void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didSelectAssets:(NSArray *)assets{
    NSMutableArray *marray=[NSMutableArray array];
    
    [self dismissViewControllerAnimated:YES completion:^{
        for (ALAsset *asset in assets) {
            
            UIImage *image=[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]];
            [marray addObject:image];
            
        }
        NSIndexPath *indexpath=[self.tableView indexPathForCell:self.currtcell];
        NSArray *array=self.dataarray[indexpath.section];
        CarpubMode *photomode=array[indexpath.row];
        photomode.ischange=YES;
        if (self.button.isSelected) {
            [photomode.imgarray replaceObjectAtIndex:self.button.tag withObject:marray[0]];
        }else{
            
            [photomode.imgarray addObjectsFromArray:marray];
        }
       
        [self.tableView reloadRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationAutomatic];
    }];
    
}


- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        
        [cell setSeparatorInset:UIEdgeInsetsZero];
        
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        
        [cell setLayoutMargins:UIEdgeInsetsZero];
        
    }
    
    
    
}
-(void)photoCellViewReloadImage:(addCarImagePickerTableViewCell *)cell{
    NSIndexPath *indexpath=[self.tableView indexPathForCell:cell];
    
    [self.tableView reloadRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *array=self.dataarray[indexPath.section];
    Pubmode *mode=array[indexPath.row];
    if ([mode isKindOfClass:[CarpubMode class]]) {
        CarpubMode *carmode=mode;
        if (carmode.imgarray.count>=4) {
            return 144;
        }else{
           return 60+16;
        }
    }
    
    if (mode.rowheight!=0){
        return mode.rowheight;
    }else{
        return 44;
    }
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
